Skip to content

fix(www): prevent command menu copy shortcut from hijacking clipboard when closed#10423

Open
yogeshwaran-c wants to merge 1 commit intoshadcn-ui:mainfrom
yogeshwaran-c:fix/command-menu-copy-when-closed
Open

fix(www): prevent command menu copy shortcut from hijacking clipboard when closed#10423
yogeshwaran-c wants to merge 1 commit intoshadcn-ui:mainfrom
yogeshwaran-c:fix/command-menu-copy-when-closed

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

The docs site command menu (apps/v4/components/command-menu.tsx) installs a global keydown listener that listens for Ctrl/Cmd+C. The handler fires regardless of whether the dialog is open, so after the user opens the search, highlights a component/color/block and then closes the dialog, every subsequent Ctrl/Cmd+C on the rest of the page copies the last highlighted item's copyPayload instead of the user's selected text. If the dialog is opened without anything being highlighted (copyPayload is an empty string), Ctrl/Cmd+C writes an empty string to the clipboard, effectively clearing it.

Closes #9242

What is the new behavior?

The Ctrl/Cmd+C branch now early-returns unless the dialog is currently open and a non-empty copyPayload is staged. The open state is read through a ref that is kept in sync via a small effect, so the handler does not need to resubscribe on every open/close toggle.

Additional context

  • Scoped to the docs site, no registry or CLI code is touched.
  • The e.preventDefault() behavior is unchanged; browser default copy is no longer pre-empted when the menu is closed.
  • apps/v4 is in the changesets ignore list, so no changeset is needed.

… when closed

The Ctrl/Cmd+C handler in the docs command menu fires globally and copies
the last highlighted item's payload regardless of whether the dialog is
open, overriding normal clipboard copies on the rest of the page. When
no item was highlighted it would also copy an empty string, effectively
clearing the clipboard.

Gate the copy branch on the dialog being open and a non-empty payload,
using a ref to read the latest open state without resubscribing on every
toggle.

Fixes shadcn-ui#9242
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 17, 2026

@yogeshwaran-c is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Searching breaks Copying in the page

1 participant